<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
	
<div class="modal fade" id="edit_warehouse_info" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document" style="width: 620px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<div class="page_header"><a>编辑仓库</a></div>
			</div>
			<form id="edit_warehouse_form">
				<input type="hidden" id="warehousemanagementid" name="warehousemanagementid" class="form-control">
				<div class="box modal-body">
					<p>
							<label class="must">仓库代码</label>
							<input type="text"   id="warehousecode"></input>
							<label class="must">仓库名称</label>
							<input type="text" name="warehousename" id="warehousename" class="form-control"></input>
					</p>
					<p>
							<label class="must">联系方式</label>
							<input type="text" name="telephone" id="telephone" class="form-control"></input>
							<label class="must">状态</label>
							<select name="status" id="status" class="form-control select">
								<option value="可用">可用</option>
								<option value="不可用">不可用</option>
							</select>
					</p>
					<p>
							<label class="must">地址</label>
							<input type="text"  name="address" id="address" class="form-control"></input>
					</p>
					<p>
							<label class="must">备注</label>
							<input type="text"  name="remarks" id="remarks" class="form-control"></input>
					</p>
					<p>
							<label>创建时间</label>
							<input type="text" readonly id="createdate" class="form-control"></input>
							<label>创建人</label>
							<input type="text" readonly id="createpersonname" class="form-control"></input>
					</p>
				</div>
			</form>
			<div class="red" id="edit_warehouse_msg" style="text-align:center;" ></div>
			<div class="modal-footer">
				<c:if test="${isEdit }">
					<button type="button"  onclick="saveEidtWarehouse();" class="btn btn1">保存</button>
				</c:if>
				<button type="button"  data-dismiss="modal" class="btn btn1">取消</button>
			</div>
		</div>
	</div>
</div>
<script>
function editWarehouse(id){
	$('#edit_warehouse_info input:hidden').val("");
	$('#edit_warehouse_info input:text').val("");
	$("#edit_warehouse_info select").val("");
	$.ajax({
		url:"<%=basePath %>warehouse/findWarehouseById.do",
		type:"post",
		async : false,
		dataType:"json",
		data:"warehousemanagementid="+id,
		success:function(data){
			for(var key in data){
				$('#edit_warehouse_info #'+key).val(data[key]);
			}
			var date=new Date();
			date.setTime(data.createdate);
			$("#edit_supplier_info #createdate").val(date.format('yyyy-MM-dd HH:mm:ss'));
		}
	});
	$('#edit_warehouse_info').modal('show');
}
function saveEidtWarehouse(){
	
	if(!validateAddForm()) return ;//校验
	
	$.ajax({
		url:"<%=basePath %>warehouse/update.do",
		type:"post",
		async : false,
		dataType:"json",
		data : $("#edit_warehouse_form").serialize(),
		success:function(data){
			if(data.result=="success"){
				$("#edit_warehouse_msg").html("");
				$('#edit_warehouse_info :text').val("");
				$("#edit_warehouse_info select").val("");
				$('#edit_warehouse_info').modal('hide');
				location.href=location.href;
			}else{
				$("#edit_warehouse_msg").html("修改仓库信息失败：",data.error);
			}
		},
		error :function(){
			$("#edit_warehouse_msg").html("修改仓库信息失败！")
		}
	});
}

//仓库管理校验
function validateAddForm(){
	
/* 	 if(!validateString("仓库代码","edit_warehouse_form [name='warehousecode']",30,false)){
		return false;
	} */
	
	if(!validateString("仓库名称","#edit_warehouse_form [name='warehousename']",30,false)){
		return false;
	} 
	
	if(!validateRegex("联系方式","#edit_warehouse_form [name='telephone']",/^1[0-9]{10}$/,false)){
		return false;
	}
	
	 if(!validateSelect("状态","#edit_warehouse_form [name='status']",120,false)){
		return false;
	}
	
	if(!validateString("地址","#edit_warehouse_form [name='address']",120,false)){
		return false;
	}
	
	if(!validateString("备注","#edit_warehouse_form [name='remarks']",190,false)){
		return false;
	} 
	
/* 	if(!validateString("创建时间","#edit_warehouse_form [name='remarks']",190,false)){
		return false;
	} 
	
	if(!validateString("创建人","#edit_warehouse_form [name='remarks']",190,false)){
		return false;
	}  */
	return true;
}



</script>